﻿#region MIT Licenze
//The MIT License

//Copyright (c) 2008 Sebastian Faltoni, dotnetfireball.org

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Fireball.OpenXML.Word
{
    public enum GridType
    {
        Default,
        Lines,
        LinesAndChars,
        SnapsToChars
    }

    /// <summary>
    /// Store the information about the document grid
    /// </summary>
    public sealed class DocGrid : OpenXMLEntity
    {
        /// <summary>
        /// Document character Pitch Decimal Number Space
        /// </summary>
        public int CharSpace { get; set; }
        /// <summary>
        /// Document line Pitch Decimal Number Space
        /// </summary>
        public int LineSpace { get; set; }

        /// <summary>
        /// Document Grid Type
        /// </summary>
        public GridType Type { get; set; }


        public override XContainer ToXml()
        {
            throw new NotImplementedException();
        }
    }

    public class SectionProperties : OpenXMLEntity
    {
        public override System.Xml.Linq.XContainer ToXml()
        {
            //TODO: Vedere come salvare i valori hesadecimali

            XElement xSectPtr = new XElement(NS.WM + "sectPtr",
                new XAttribute(NS.WM + "rsidDel", this.SectionDeletionRevisionID),
                new XAttribute(NS.WM + "rsidR", this.SectionAdditionRevisionID),
                new XAttribute(NS.WM + "rsidRPr", this.PhysicalSectionMarkCharacterRevisionID));

            xSectPtr.Add(new XElement(NS.WM +"bidi",new XAttribute(NS.WM+"val",this.Bidi.ToOnOff())));

            if(this.DocGrid != null)
                xSectPtr.Add(this.DocGrid.ToXml());

            if (!string.IsNullOrEmpty(this.PrinterSettingsID))
                xSectPtr.Add(new XElement(NS.WM + "printerSettings",
                    new XAttribute(NS.RS + "id", this.PrinterSettingsID)));

            if(this.Change!= null)
                xSectPtr.Add(this.Change.ToXml());

            return xSectPtr;
        }

        // 4 digit Hexadecimanl number value
        public int SectionDeletionRevisionID
        {
            get;
            set;
        }

        // 4 digit Hexadecimanl number value
        public int SectionAdditionRevisionID
        {
            get;
            set;
        }

        // 4 digit Hexadecimanl number value
        public int PhysicalSectionMarkCharacterRevisionID
        {
            get;
            set;
        }

        // SectionPropertiesRevisionID
        public int SectionPropertiesRevisionID
        {
            get;
            set;
        }

        /// <summary>
        /// Right to left section layout
        /// </summary>
        public bool Bidi
        {
            get;
            set;
        }

        public DocGrid DocGrid
        {
            get;
            set;
        }

        /// <summary>
        /// PrinterSettings RelationsShipID
        /// </summary>
        public string PrinterSettingsID
        {
            get;
            set;
        }

        public SectionRevisionInformation Change
        {
            get;
            set;
        }
    }
}
